'''
Descripttion: 
version: 
Author: Born
Date: 2020-11-18 10:57:37
LastEditors: Born
'''

from django.shortcuts import HttpResponseRedirect
from django.conf import settings
import re

try:
    from django.utils.deprecation import MiddlewareMixin  # Django 1.10.x
except ImportError:
    MiddlewareMixin = object  # Django 1.4.x - Django 1.9.x
 
 
class SimpleMiddleware(MiddlewareMixin):
    def process_request(self, request):
        allowApplication = ['caslogin','dashboard','datacenter']
        application = request.path.split('/')[1]
        # 先判断是否需要验证
        if(not application in allowApplication):
            # 如果需要验证，判断是否登录
            if(not request.user.is_authenticated):
                return HttpResponseRedirect(settings.LOGIN_URL)